package com.woniu.service.serviceImpl;

import com.woniu.dao.*;
import com.woniu.dto.HotCommentsDTO;
import com.woniu.dto.HotDetailDTO;
import com.woniu.dto.HotListDTO;
import com.woniu.pojo.*;
import com.woniu.service.HotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class HotServiceImpl implements HotService {
    @Autowired
    private HotListMapper listMapper;
    @Autowired
    private HotListDetailMapper detailMapper;
    @Autowired
    private HotCollectMapper collectMapper;
    @Autowired
    private HotCommentsMapper commentsMapper;
    @Autowired
    private ComplainMapper complainMapper;
    @Override
    public void addHot(HotList hotList) {
        listMapper.insert(hotList);
    }

    @Override
    public List<HotListDTO> selectDTOByPage(Integer currentPage, Integer pageSize) {

        return listMapper.selectHotList(currentPage,pageSize);
    }

    @Override
    public HotDetailDTO selectHotDetail(Long hotId) {
        return listMapper.selectHotDetail(hotId);
    }

    @Override
    public HotListDetail selectHot(Long hotId, Long userId) {
        return listMapper.selectHot(hotId,userId);
    }

    @Override
    public Integer selectRealNum(Long hotId) {
        return listMapper.selectRealNum(hotId);
    }

    @Override
    public Integer selectPersonNum(Long hotId) {
        return listMapper.selectNumber(hotId);
    }

    @Override
    public void hotApply(HotListDetail detail) {
        detailMapper.insertSelective(detail);
    }

    @Override
    public void hotCollect(Long hotId, Long userId) {
        HotCollect hotCollect = new HotCollect();
 hotCollect.setCreatTime(new Date());
 hotCollect.setHotId(hotId);
 hotCollect.setUserId(userId);
 collectMapper.insertSelective(hotCollect);
    }

    @Override
    public HotCollect selectHotCollect(Long hotId, Long userId) {
        return collectMapper.selectCollect(hotId,userId);
    }

    @Override
    public void reduceHotCollect(Long hotId, Long userId) {
         collectMapper.deleteCollect(hotId,userId);
    }

    @Override
    public List<HotCommentsDTO> selectHotComment(Long hotId) {
        return commentsMapper.selectHotComment(hotId);
    }

    @Override
    public void addHotComment(HotComments comments) {
        commentsMapper.insertSelective(comments);
    }

    @Override
    public List<String> selectHotPerson(Long hotId) {
        return detailMapper.selectHotPerson(hotId);
    }

    @Override
    public void addReport(Complain complain) {
        complainMapper.insertSelective(complain);
    }

    @Override
    public Date selectTime(Long hotId) {

        return listMapper.selectHotStartTime(hotId);
    }

    @Override
    public List<HotListDTO> selectFriendHot(List<Long> friendsId) {
        return listMapper.selectFriendHot(friendsId);
    }

    @Override
    public HotList selectHotShow(Long hotId) {
        return listMapper.selectByPrimaryKey(hotId);
    }

    @Override
    public Date selectStartTime(Long id) {
        return listMapper.selectTime(id);
    }

    @Override
    public void updateHot(HotList hotList) {
        listMapper.updateByPrimaryKey(hotList);
    }

    @Override
    public Date selectHotEndTime(Long hotId) {
        return listMapper.selectEndTime(hotId);
    }

    @Override
    public void deleteHot(Long hotId) {
        listMapper.deleteByPrimaryKey(hotId);
        collectMapper.delete(hotId);
        commentsMapper.delete(hotId);
        commentsMapper.deleteTag(hotId);
        commentsMapper.deleteGrade(hotId);
    }

    @Override
    public void deleteComment(Long commentId) {
        commentsMapper.deleteByPrimaryKey(commentId);
    }

    @Override
    public List<HotListDTO> selectLastestHot() {
        return listMapper.selectLastestHot();
    }
}
